import React from 'react'
import Loadable from 'react-loadable'

const files = require.context('@/views', true, /\.tsx$/)
export const conventionRoute = files.keys().map(key => {
  const component = Loadable({
    loader: () => import(`@/views/${key.replace('./', '')}`),
    loading: () => null
  })
  if (key.includes('[') && key.includes(']')) {
    return {
      path: key.replace('./', '').replace('.tsx', '').replace('[', ':').replace(']', ''),
      element: React.createElement(component)
    }
  } else {
    return {
      path: key.replace('./', '').replace('.tsx', '').replace("/index", ""),
      element: React.createElement(component)
    }
  }
})
